package com.ruoyi.ruoyiserver.service.impl;

import com.alibaba.excel.EasyExcel;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fasterxml.jackson.databind.exc.InvalidFormatException;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.ruoyiserver.domain.*;
import com.ruoyi.ruoyiserver.listener.PeDataInformationListener;
import com.ruoyi.ruoyiserver.mapper.*;
import com.ruoyi.ruoyiserver.service.*;
import com.ruoyi.ruoyiserver.vo.TeacherInformationEntity;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.*;

@Service
@Slf4j
@Component
public class TeacherInformationServiceImpl extends ServiceImpl<TeacherInformationMapper,TeacherInformationEntity> implements TeacherInformationService {

    @Resource
    private PeTeacherInformationMapper peTeacherInformationMapper;
    @Resource
    private IPeTeacherInformationService teacherInformationService;
    @Resource
    private IPeStudentInformationService studentInformationService;
    @Resource
    private PeDataInformationMapper dataInformationMapper;
    @Resource
    private PeStudentInformationMapper studentInformationMapper;
    @Resource
    private PeTabInformationMapper tabInformationMapper;
    @Resource
    private IPeTabInformationService tabInformationService;
    @Resource
    private IPeObligeeInformtionService iPeObligeeInformtionService;
    @Resource
    private PeObligeeInformtionMapper obligeeInformtionMapper;
    @Autowired
    private PeRecordService peRecordService;

    @Override
    public AjaxResult importExcel(MultipartFile multipartFile) throws IOException {
        try {
            int a = 0;
            int b = 0;
            ArrayList<String> list1 = new ArrayList<>();
            List<PeTeacherInformation> teacherInformationEntities = teacherExcel2Model(multipartFile);
            List<PeTeacherInformation> peTeacherInformations = peTeacherInformationMapper.selectList(new LambdaQueryWrapper<>());
            for (PeTeacherInformation teacherInformationEntity : peTeacherInformations) {
                list1.add(teacherInformationEntity.getIdNumber());
            }
            for (PeTeacherInformation teacherInformationEntity : teacherInformationEntities) {
                /** 判重*/
                if (list1.contains(teacherInformationEntity.getIdNumber())){
                    return AjaxResult.error("表格中与数据库中有重复数据，重复数据的身份证号为："+teacherInformationEntity.getIdNumber());
                }
                int i = peTeacherInformationMapper.insertPeTeacherInformation(teacherInformationEntity);
                if (i==1){
                    a += 1;
                }else{
                    b += 1;
                }
            }
            if (b==0) {
                return AjaxResult.success("数据导入成功，成功导入"+a+"条数据");
            } else {
                return AjaxResult.error("数据成功导入"+a+"条数据，未成功导入"+b+"条数据");
            }
        } catch (Exception e) {
            return AjaxResult.error("数据导入失败，请检查模版是否正确");
        }
    }
    public List<PeTeacherInformation> teacherExcel2Model(MultipartFile multipartFile) throws IOException, InvalidFormatException {
        List<PeTeacherInformation> result = new ArrayList<>();

        InputStream inputStream = multipartFile.getInputStream();
        Workbook workbook = WorkbookFactory.create(inputStream);
        Sheet sheet = workbook.getSheetAt(0);

        Iterator<Row> rowIterator = sheet.iterator();

        if (rowIterator.hasNext()) {
           Row row = rowIterator.next();
            String beiZhu = getStringCellValue(row.getCell(9));
            if (!beiZhu.equals("备注")){
                throw new RuntimeException("模板导入不正确，请检查模板");
            }
        }

        while (rowIterator.hasNext()) {

            Row row = rowIterator.next();
            PeTeacherInformation model = new PeTeacherInformation();
//            String stringCellValue = getStringCellValue((row.getCell(0)));
            String substring = UUID.randomUUID().toString().replace("-", "").substring(0, 10);
            model.setId(substring);
            model.setSchoolName(getStringCellValue(row.getCell(1)));
            model.setName(getStringCellValue(row.getCell(2)));
            model.setIdNumber(getStringCellValue(row.getCell(3)));
            model.setNativePlace(getStringCellValue(row.getCell(4)));
            model.setAddress(getStringCellValue(row.getCell(5)));
            model.setPhone(getStringCellValue(row.getCell(6)));
            model.setHomeName(getStringCellValue(row.getCell(7)));
            model.setHomePhone(getStringCellValue(row.getCell(8)));
            model.setRemark(getStringCellValue(row.getCell(9)));
            //model.setReportNumber(getStringCellValue(row.getCell(4)));
            result.add(model);
        }

        workbook.close();
        inputStream.close();

        return result;
    }

    private String getStringCellValue(Cell cell) {
        if (cell == null) {
            return "";
        }
        // 如果是数字类型且看起来像身份证号的格式，强制转换为字符串
        if (cell.getCellType() == CellType.NUMERIC) {
            DecimalFormat decimalFormat = new DecimalFormat("0");
            return decimalFormat.format(cell.getNumericCellValue());
        }
        cell.setCellType(CellType.STRING);
        return cell.getStringCellValue().trim();
    }
    private Date getDataCellValue(Cell cell){
        if (cell == null){
            return null;
        }
        switch (cell.getCellTypeEnum()) {
            case NUMERIC:
                // 如果单元格类型是数字，可能是日期格式
                if (DateUtil.isCellDateFormatted(cell)) {
                    return cell.getDateCellValue();  // 如果是日期，直接返回日期
                } else {
                    // 如果是数字类型但不是日期格式，可以根据需要返回数值或者处理为其他类型
                    return new Date((long) cell.getNumericCellValue());
                }
            case STRING:
                // 如果单元格类型是字符串，尝试将其解析为日期
                String dateStr = cell.getStringCellValue().trim();
                if (!dateStr.isEmpty()) {
                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日"); // 或者根据需要修改日期格式
                    try {
                        return sdf.parse(dateStr);
                    } catch (Exception e) {
                        // 如果解析失败，返回 null 或抛出异常
                        e.printStackTrace();
                        return null;
                    }
                }
                break;
        }
        return null;
    }

    public byte[] generateExcelFile() throws IOException {

        LambdaQueryWrapper<PeTeacherInformation> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.orderByAsc(PeTeacherInformation::getId);
        List<PeTeacherInformation> peTeacherInformationList = peTeacherInformationMapper.selectList(lambdaQueryWrapper);

        try (Workbook workbook = new XSSFWorkbook()) {
            Sheet sheet = workbook.createSheet("公办学校教职工信息采集表");
            String[] headers = {"序号", "学校名称", "姓名", "身份证号码", "籍贯", "现住址", "联系电话", "家庭成员姓名", "家庭成员联系电话", "备注"};
            Row headerRow = sheet.createRow(0);

            CellStyle headerStyle = workbook.createCellStyle();
            Font font = workbook.createFont();
            font.setBold(true);
            headerStyle.setFont(font);

            for (int i = 0; i < headers.length; i++) {
                Cell cell = headerRow.createCell(i);
                cell.setCellValue(headers[i]);
                cell.setCellStyle(headerStyle);
            }

            int rowNum = 1;
            for (PeTeacherInformation model : peTeacherInformationList) {
                Row row = sheet.createRow(rowNum++);
                row.createCell(0).setCellValue(model.getId());
                row.createCell(1).setCellValue(model.getSchoolName());
                row.createCell(2).setCellValue(model.getName());
                //row.createCell(3).setCellValue(model.getReportNumber());
                row.createCell(3).setCellValue(model.getIdNumber());
                row.createCell(4).setCellValue(model.getNativePlace());
                row.createCell(5).setCellValue(model.getAddress());
                row.createCell(6).setCellValue(model.getPhone());
                row.createCell(7).setCellValue(model.getHomeName());
                row.createCell(8).setCellValue(model.getHomePhone());
                row.createCell(9).setCellValue(model.getRemark());
            }

            for (int i = 0; i < headers.length; i++) {
                sheet.autoSizeColumn(i);
            }

            try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
                workbook.write(outputStream);
                return outputStream.toByteArray();
            }
        }
    }

    @Override
    public AjaxResult importStudentExcel(MultipartFile file) throws IOException{
        try {
            int a = 0;
            int b = 0;
            ArrayList<String> list1 = new ArrayList<>();
            List<PeStudentInformation> studentInformations = studentExcel2Model(file);
            List<PeStudentInformation> studentInformations1 = studentInformationMapper.selectList(new LambdaQueryWrapper<>());
            for (PeStudentInformation teacherInformationEntity : studentInformations1) {
                list1.add(teacherInformationEntity.getIdNumber());
            }
            for (PeStudentInformation teacherInformationEntity : studentInformations) {
                /** 判重*/
                if (list1.contains(teacherInformationEntity.getIdNumber())){
                    return AjaxResult.error("表格中与数据库中有重复数据，重复数据的身份证号为："+teacherInformationEntity.getIdNumber());
                }
                int i = studentInformationMapper.insertPeStudentInformation(teacherInformationEntity);
                if (i==1){
                    a += 1;
                }else{
                    b += 1;
                }
            }
            if (b==0) {
                return AjaxResult.success("数据导入成功，成功导入"+a+"条数据");
            } else {
                return AjaxResult.error("数据成功导入"+a+"条数据，未成功导入"+b+"条数据");
            }
        } catch (Exception e) {
            return AjaxResult.error("数据导入失败，请检查模版是否正确");
        }
    }

    public List<PeStudentInformation> studentExcel2Model(MultipartFile multipartFile) throws IOException{
        List<PeStudentInformation> result = new ArrayList<>();

        InputStream inputStream = multipartFile.getInputStream();
        Workbook workbook = WorkbookFactory.create(inputStream);
        Sheet sheet = workbook.getSheetAt(0);

        Iterator<Row> rowIterator = sheet.iterator();
        if (rowIterator.hasNext()) {
            Row row = rowIterator.next();
            String studentName = getStringCellValue(row.getCell(2));
            if (!studentName.equals("学生姓名")){
                throw new RuntimeException("模板不正确");
            }

        }

        while (rowIterator.hasNext()) {
            Row row = rowIterator.next();

            PeStudentInformation model = new PeStudentInformation();
            model.setId(UUID.randomUUID().toString().replace("-","").substring(0,20));
            model.setSchoolName(getStringCellValue(row.getCell(1)));
            model.setName(getStringCellValue(row.getCell(2)));
            model.setGrade(getStringCellValue(row.getCell(3)));
            model.setIdNumber(getStringCellValue(row.getCell(4)));
            model.setNativePlace(getStringCellValue(row.getCell(5)));
            model.setHomeAddress(getStringCellValue(row.getCell(6)));
            model.setPhone(getStringCellValue(row.getCell(7)));
            model.setHomeName(getStringCellValue(row.getCell(8)));
            model.setHomePhone(getStringCellValue(row.getCell(9)));
            //model.setReportNumber(getStringCellValue(row.getCell(4)));
            result.add(model);
        }

        workbook.close();
        inputStream.close();

        return result;
    }

    public byte[] studentExcelFile() throws IOException {

        LambdaQueryWrapper<PeStudentInformation> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        List<PeStudentInformation> studentInformationList = studentInformationMapper.selectList(lambdaQueryWrapper);

        try (Workbook workbook = new XSSFWorkbook()) {
            Sheet sheet = workbook.createSheet("学校学生信息采集表");
            String[] headers = {"序号", "学校名称", "学生姓名", "年纪", "身份证号码", "籍贯", "家庭住址", "联系电话", "家庭成员姓名", "家庭成员联系电话"};
            Row headerRow = sheet.createRow(0);

            CellStyle headerStyle = workbook.createCellStyle();
            Font font = workbook.createFont();
            font.setBold(true);
            headerStyle.setFont(font);

            for (int i = 0; i < headers.length; i++) {
                Cell cell = headerRow.createCell(i);
                cell.setCellValue(headers[i]);
                cell.setCellStyle(headerStyle);
            }

            int rowNum = 1;
            for (PeStudentInformation model : studentInformationList) {
                Row row = sheet.createRow(rowNum++);
                row.createCell(0).setCellValue(model.getId());
                row.createCell(1).setCellValue(model.getSchoolName());
                row.createCell(2).setCellValue(model.getName());
                //row.createCell(3).setCellValue(model.getReportNumber());
                row.createCell(3).setCellValue(model.getGrade());
                row.createCell(4).setCellValue(model.getIdNumber());
                row.createCell(5).setCellValue(model.getNativePlace());
                row.createCell(6).setCellValue(model.getHomeAddress());
                row.createCell(7).setCellValue(model.getPhone());
                row.createCell(8).setCellValue(model.getHomeName());
                row.createCell(9).setCellValue(model.getHomePhone());
            }

            for (int i = 0; i < headers.length; i++) {
                sheet.autoSizeColumn(i);
            }

            try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
                workbook.write(outputStream);
                return outputStream.toByteArray();
            }
        }
    }

    @Override
    public AjaxResult importObligeeExcel(MultipartFile file) throws IOException{
        try {
            int a = 0;
            int b = 0;
            ArrayList<String> list1 = new ArrayList<>();
            List<PeObligeeInformtion> obligeeInformtions = obligeeExcel2Model(file);
            List<PeObligeeInformtion> obligeeInformtions1 = obligeeInformtionMapper.selectList(new LambdaQueryWrapper<>());
            for (PeObligeeInformtion teacherInformationEntity : obligeeInformtions1) {
                list1.add(teacherInformationEntity.getIdNumber());
            }
            for (PeObligeeInformtion teacherInformationEntity : obligeeInformtions) {
                /** 判重*/
                if (list1.contains(teacherInformationEntity.getIdNumber())){
                    return AjaxResult.error("表格中与数据库中有重复数据，重复数据的身份证号为："+teacherInformationEntity.getIdNumber());
                }
                int i = obligeeInformtionMapper.insertPeObligeeInformtion(teacherInformationEntity);
                if (i==1){
                    a += 1;
                }else{
                    b += 1;
                }
            }
            if (b==0) {
                return AjaxResult.success("数据导入成功，成功导入"+a+"条数据");
            } else {
                return AjaxResult.error("数据成功导入"+a+"条数据，未成功导入"+b+"条数据");
            }
        } catch (Exception e) {
            return AjaxResult.error("数据导入失败，请检查模版是否正确");
        }
    }
    public List<PeObligeeInformtion> obligeeExcel2Model(MultipartFile multipartFile) throws IOException, InvalidFormatException {
        List<PeObligeeInformtion> result = new ArrayList<>();

        InputStream inputStream = multipartFile.getInputStream();
        Workbook workbook = WorkbookFactory.create(inputStream);
        Sheet sheet = workbook.getSheetAt(0);

        Iterator<Row> rowIterator = sheet.iterator();
        if (rowIterator.hasNext()) {
           Row row = rowIterator.next();
            String cellValue = getStringCellValue(row.getCell(5));
            if (!cellValue.equals("登记时间")){
                throw new RuntimeException("模板错误");
            }
        }

        while (rowIterator.hasNext()) {
            Row row = rowIterator.next();
            PeObligeeInformtion model = new PeObligeeInformtion();
            String substring = UUID.randomUUID().toString().replace("-", "").substring(0, 10);
            model.setId(substring);
            model.setAbligee(getStringCellValue(row.getCell(1)));
            model.setIdNumber(getStringCellValue(row.getCell(2)));
            model.setPhone(getStringCellValue(row.getCell(3)));
            model.setAddress(getStringCellValue(row.getCell(4)));
            Date data = getDataCellValue(row.getCell(5));
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy年MM月dd日");
            String format = simpleDateFormat.format(data);
            model.setRegistDate(format);
            //model.setReportNumber(getStringCellValue(row.getCell(4)));
            result.add(model);
        }

        workbook.close();
        inputStream.close();

        return result;
    }

    @Override
    public byte[] generateObligeeExcelFile() throws IOException{
        LambdaQueryWrapper<PeObligeeInformtion> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        List<PeObligeeInformtion> obligeeInformationList = obligeeInformtionMapper.selectList(lambdaQueryWrapper);

        try (Workbook workbook = new XSSFWorkbook()) {
            Sheet sheet = workbook.createSheet("权利人信息表");
            String[] headers = {"序号", "权利人", "身份证号", "电话", "坐落", "登记时间"};
            Row headerRow = sheet.createRow(0);

            CellStyle headerStyle = workbook.createCellStyle();
            Font font = workbook.createFont();
            font.setBold(true);
            headerStyle.setFont(font);

            for (int i = 0; i < headers.length; i++) {
                Cell cell = headerRow.createCell(i);
                cell.setCellValue(headers[i]);
                cell.setCellStyle(headerStyle);
            }

            int rowNum = 1;
            for (PeObligeeInformtion model : obligeeInformationList) {
                Row row = sheet.createRow(rowNum++);
                row.createCell(0).setCellValue(model.getId());
                row.createCell(1).setCellValue(model.getAbligee());
                row.createCell(2).setCellValue(model.getIdNumber());
                //row.createCell(3).setCellValue(model.getReportNumber());
                row.createCell(3).setCellValue(model.getPhone());
                row.createCell(4).setCellValue(model.getAddress());
                row.createCell(5).setCellValue(model.getRegistDate());
            }

            for (int i = 0; i < headers.length; i++) {
                sheet.autoSizeColumn(i);
            }

            try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
                workbook.write(outputStream);
                return outputStream.toByteArray();
            }
        }
    }

    @Override
    public AjaxResult importTabExcel(MultipartFile file) throws IOException {
        try {
            int a = 0;
            int b = 0;
            ArrayList<String> list1 = new ArrayList<>();
            List<PeTabInformation> tabInformations = tabExcel2Model(file);
            List<PeTabInformation> tabInformations1 = tabInformationMapper.selectList(new LambdaQueryWrapper<>());
            for (PeTabInformation tabInformation : tabInformations1) {
                list1.add(tabInformation.getIdNumber());
            }
            for (PeTabInformation teacherInformationEntity : tabInformations) {
                /** 判重*/
                if (list1.contains(teacherInformationEntity.getIdNumber())){
                    return AjaxResult.error("表格中与数据库中有重复数据，重复数据的身份证号为："+teacherInformationEntity.getIdNumber());
                }
                int i = tabInformationMapper.insertPeTabInformation(teacherInformationEntity);
                if (i==1){
                    a += 1;
                }else{
                    b += 1;
                }
            }
            if (b==0) {
                return AjaxResult.success("数据导入成功，成功导入"+a+"条数据");
            } else {
                return AjaxResult.error("数据成功导入"+a+"条数据，未成功导入"+b+"条数据");
            }
        } catch (Exception e) {
            return AjaxResult.error("数据导入失败，请检查模版是否正确");
        }
    }
    public List<PeTabInformation> tabExcel2Model(MultipartFile multipartFile) throws IOException, InvalidFormatException {
        List<PeTabInformation> result = new ArrayList<>();

        InputStream inputStream = multipartFile.getInputStream();
        Workbook workbook = WorkbookFactory.create(inputStream);
        Sheet sheet = workbook.getSheetAt(0);

        Iterator<Row> rowIterator = sheet.iterator();
        if (rowIterator.hasNext()) {
            Row row = rowIterator.next();
            String cellValue = getStringCellValue(row.getCell(7));
            if (!cellValue.equals("签订时间")){
                throw new RuntimeException("模板不正确");
            }
        }

        while (rowIterator.hasNext()) {
            Row row = rowIterator.next();
            PeTabInformation model = new PeTabInformation();
            String substring = UUID.randomUUID().toString().replace("-", "").substring(0, 10);
            model.setId(substring);
            model.setHomeAddress(getStringCellValue(row.getCell(1)));
            model.setHomebuyer(getStringCellValue(row.getCell(2)));
            model.setIdNumber(getStringCellValue(row.getCell(3)));
            model.setHomebuyerAddress(getStringCellValue(row.getCell(4)));
            model.setSex(getStringCellValue(row.getCell(5)));
            model.setProgramme(getStringCellValue(row.getCell(6)));
            Date data = getDataCellValue(row.getCell(7));
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy年MM月dd日");
            String format = simpleDateFormat.format(data);
            model.setSignDate(format);
            //model.setReportNumber(getStringCellValue(row.getCell(4)));
            result.add(model);
        }

        workbook.close();
        inputStream.close();

        return result;
    }

    @Override
    public byte[] generateTabExcelFile() throws IOException {
        LambdaQueryWrapper<PeTabInformation> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        List<PeTabInformation> tabInformationList = tabInformationMapper.selectList(lambdaQueryWrapper);

        try (Workbook workbook = new XSSFWorkbook()) {
            Sheet sheet = workbook.createSheet("网签信息表");
            String[] headers = {"序号", "住房地址", "购房人", "身份证号", "购房人住址", "性别", "规划用途", "签订时间"};
            Row headerRow = sheet.createRow(0);

            CellStyle headerStyle = workbook.createCellStyle();
            Font font = workbook.createFont();
            font.setBold(true);
            headerStyle.setFont(font);

            for (int i = 0; i < headers.length; i++) {
                Cell cell = headerRow.createCell(i);
                cell.setCellValue(headers[i]);
                cell.setCellStyle(headerStyle);
            }

            int rowNum = 1;
            for (PeTabInformation model : tabInformationList) {
                Row row = sheet.createRow(rowNum++);
                row.createCell(0).setCellValue(model.getId());
                row.createCell(1).setCellValue(model.getHomeAddress());
                row.createCell(2).setCellValue(model.getHomebuyer());
                row.createCell(3).setCellValue(model.getIdNumber());
                row.createCell(4).setCellValue(model.getHomebuyerAddress());
                row.createCell(5).setCellValue(model.getSex());
                row.createCell(6).setCellValue(model.getProgramme());
                row.createCell(7).setCellValue(model.getSignDate());
            }

            for (int i = 0; i < headers.length; i++) {
                sheet.autoSizeColumn(i);
            }

            try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
                workbook.write(outputStream);
                return outputStream.toByteArray();
            }
        }
    }

//    @Async
    /*@Override
    public AjaxResult importInformation(MultipartFile file) throws IOException {
        try {

            List<PeDataInformation> dataInformation = informationExcel2Model(file);
            int batchSize = 1000;
            int total = dataInformation.size();
            for (int i = 0; i < total; i += batchSize) {
                int end = Math.min(i + batchSize, total);
                List<PeDataInformation> batch = dataInformation.subList(i, end);
                dataInformationMapper.insertBatchData(batch);
            }

            return AjaxResult.success("数据导入成功");
        } catch (Exception e) {
            return AjaxResult.error("数据导入失败，请检查模版是否正确");
        }
    }
    public List<PeDataInformation> informationExcel2Model(MultipartFile multipartFile) throws IOException, InvalidFormatException {
        List<PeDataInformation> result = new ArrayList<>();

        InputStream inputStream = multipartFile.getInputStream();
        Workbook workbook = WorkbookFactory.create(inputStream);
        Sheet sheet = workbook.getSheetAt(0);

        Iterator<Row> rowIterator = sheet.iterator();
        if (rowIterator.hasNext()) {
            Row row = rowIterator.next();
            String cellValue = getStringCellValue(row.getCell(9));
            if (!cellValue.equals("数据源")){
                throw new RuntimeException("模板不正确");
            }
        }

        while (rowIterator.hasNext()) {
            Row row = rowIterator.next();
            PeDataInformation model = new PeDataInformation();
            String substring = UUID.randomUUID().toString().replace("-", "").substring(0, 20);
            model.setId(substring);
            if (getStringCellValue(row.getCell(0)).isEmpty() && getStringCellValue(row.getCell(1)).isEmpty()
                && getStringCellValue(row.getCell(2)).isEmpty() && getStringCellValue(row.getCell(3)).isEmpty()
                && getStringCellValue(row.getCell(4)).isEmpty() && getStringCellValue(row.getCell(5)).isEmpty()
                && getStringCellValue(row.getCell(6)).isEmpty() && getStringCellValue(row.getCell(7)).isEmpty()
                && getStringCellValue(row.getCell(8)).isEmpty() && getStringCellValue(row.getCell(9)).isEmpty()
                && getStringCellValue(row.getCell(10)).isEmpty()){
                workbook.close();
                inputStream.close();
                return result;
            }
            model.setName(getStringCellValue(row.getCell(0)));
            model.setIdNumber(getStringCellValue(row.getCell(1)));
            model.setPhone1(getStringCellValue(row.getCell(2)));
            model.setPhone2(getStringCellValue(row.getCell(3)));
            model.setAddress1(getStringCellValue(row.getCell(4)));
            model.setAddress2(getStringCellValue(row.getCell(5)));
            model.setPerson(getStringCellValue(row.getCell(6)));
            model.setPersonPhone(getStringCellValue(row.getCell(7)));
            model.setPersonAddress(getStringCellValue(row.getCell(8)));
            model.setDataSource(getStringCellValue(row.getCell(9)));
            Date data = getDataCellValue(row.getCell(10));
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy年MM月dd日");
            String format = simpleDateFormat.format(data);
            model.setDate1(format);
            model.setRemark(getStringCellValue(row.getCell(11)));
            //model.setReportNumber(getStringCellValue(row.getCell(4)));
            result.add(model);
        }

        workbook.close();
        inputStream.close();

        return result;
    }*/
@Async
@Override
public AjaxResult importInformation(MultipartFile file) throws IOException {
    try {
        EasyExcel.read(file.getInputStream(), PeDataInformation.class, new PeDataInformationListener(dataInformationMapper))
                .sheet().doRead();
        return AjaxResult.success("数据导入成功");
    } catch (Exception e) {
        e.printStackTrace();
        return AjaxResult.error("数据导入失败，请检查模版是否正确：" + e.getMessage());
    }
}

}
